package com.zjitc.utils;

import com.zjitc.pojo.UserExtend;

import javax.servlet.http.HttpSession;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/11/13 9:16
 * @description:
 */
public class HttpSessionUtils {

    public static UserExtend getUserExtend(HttpSession session) {
        return (UserExtend) session.getAttribute("user");
    }

    public static UserExtend getUserExtend(HttpSession session, String key) {
        return (UserExtend) session.getAttribute(key);
    }

    public static boolean checkAdmin(HttpSession session){
        return true;
//
//        try {
//            return Integer.parseInt(((UserExtend) session.getAttribute("user")).getState()) > 2;
//        }catch (Exception e){
//            e.printStackTrace();
//            return false;
//        }
    }

    public static boolean checkAdmin(HttpSession session, String key){
        try {
            return Integer.parseInt(((UserExtend) session.getAttribute(key)).getState()) > 2;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
